# -*-coding = utf-8 -*-
# @Time : 2022/10/18 21:10
# @Author : Oliver
# @File : 读论文.py
# @Software :PyCharm
class Solution:
    def minimumTimeRequired(self, jobs, k: int) -> int:
        n = len(jobs)
        jobs.sort(reverse=True)

        # 深搜回溯剪枝判断是否可行
        self.ans = False

        def check(cost):
            self.ans = False

            def dfs(pre, ind):
                if self.ans:
                    return
                if ind == n:
                    self.ans = True
                    return
                for i in range(k):
                    if not pre[i]:
                        pre[i] = jobs[ind]
                        dfs(pre[:], ind + 1)
                        return
                    if pre[i] + jobs[ind] <= cost:
                        nex = pre[:]
                        nex[i] += jobs[ind]
                        dfs(nex[:], ind + 1)
                return

            # 这里有个坑，必须以数组形式传入参数，如果是原地修改会有很大的耗时性能影响
            dfs([0] * k, 0)
            return self.ans

        low = max(jobs)
        high = sum(jobs)
        while low < high - 1:
            mid = low + (high - low) // 2
            if check(mid):
                high = mid
            else:
                low = mid
        if check(low):
            return low
        return high


arr = list(map(int, input().split()))
jobs = list(map(int, input().split()))
res = Solution().minimumTimeRequired(jobs=jobs, k=arr[1])
print(res)
